<template>
  <div class="addparty_container">
   <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="活动名称" prop="name">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
  </div>
</template>
<script>
import request from '@/utils/request'
export default {
  data () {
    return {
      ruleForm: {
        name: '123'
      },
      rules: {
        name: [
          { required: true, message: '请输入派对名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 10个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      const partyname = JSON.stringify(this.ruleForm)
      console.log(partyname)

      this.$refs[formName].validate((valid) => {
        if (valid) {
          request({
            headers: {
              'Content-Type': 'application/json '
            },
            url: '/create_party',
            mathod: 'POST',
            data: this.ruleForm
          })
        } else {
          alert('error!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style scoped lang="less">
.addparty_container{
    display: flex;
    justify-content: center;
}
</style>
